import { toSuccess, useEntityManager } from "@sker/core"
import { KsAccountFollow } from "@sker/entities"
import { useData } from "@sker/runtime"
import { z } from "zod"


export default async () => {
    const input = z.object({
        from: z.string(),
        to: z.string(),
        uuid: z.string()
    })
    const body = input.parse(useData())
    await useEntityManager(async m => {
        const one = await m.findOne(KsAccountFollow, { where: { from: body.from, to: body.to } })
        const entity = m.create(KsAccountFollow, {
            id: one?.id,
            package_name: '',
            from: body.from,
            to: body.to,
            device_uuid: body.uuid
        })
        await m.save(KsAccountFollow, entity)
    })
    return toSuccess(true);
}
